FROM alpine:3.16
LABEL wanstu="wanstu@163.com"
WORKDIR /www
ADD ./resource/php-7.4.33.tar.gz /tmp
ADD ./resource/phpredis-5.3.7.tar.gz /tmp
# 安装编译 PHP 所需依赖
# 安装 phpredis 扩展
# 将 php-redis 文件移动到 扩展文件中并更名为redis
RUN echo 'https://mirrors.aliyun.com/alpine/v3.16/main' > /etc/apk/repositories \
  && echo 'https://mirrors.aliyun.com/alpine/v3.16/community' >> /etc/apk/repositories
RUN mv /tmp/phpredis-5.3.7 /tmp/php-7.4.33/ext/redis && rm /tmp/php-7.4.33/configure
# 重新生成配置文件
RUN apk add autoconf && cd /tmp/php-7.4.33 && ls && ./buildconf --force 
# 此步需要依赖 pkgconfig gcc g++ libxml2-dev openssl-dev sqlite-dev libcurl curl-dev libpng-dev oniguruma-dev
RUN apk add pkgconfig gcc g++ libxml2-dev openssl-dev sqlite-dev libcurl curl-dev libpng-dev oniguruma-dev c-ares-dev
# 配置 PHP
RUN cd /tmp/php-7.4.33 && ./configure --prefix=/usr/local/php \
  --with-config-file-path=/usr/local/php/etc \
  --enable-fpm \
  --enable-mbstring \
  --with-curl \
  --with-mysqli \
  --enable-bcmath \
  --with-openssl \
  --with-zlib \
  --enable-ftp \
  --enable-gd \
  --enable-mbstring \
  --with-pdo-mysql \
  --enable-redis \
  --enable-http2 \
  --enable-cares
RUN apk add make 
RUN cd /tmp/php-7.4.33 && make && make install
# 注册环境
RUN ln -s /usr/local/php/bin/php /usr/local/bin/php
RUN ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/php-fpm
RUN cp /tmp/php-7.4.33/php.ini-production /usr/local/php/php.ini
RUN cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf && sed -i 's#;daemonize = yes#daemonize = no#g' /usr/local/php/etc/php-fpm.conf
RUN cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# install composer
RUN cd /tmp \
  && php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" \
  && php composer-setup.php && mv composer.phar /usr/local/bin/composer \
  && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/
RUN apk add -U tzdata vim supervisor
RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
EXPOSE 80
CMD ["php-fpm"]